package net.hpxn.gsmc.core.server;

import net.hpxn.gsmc.config.server.ServerConfigs.ServerConfig;

public class ServerFactory {
	private static volatile ServerFactory INSTANCE;

	public static ServerFactory getInstance() {
		if ( INSTANCE == null ) {
			synchronized ( ServerFactory.class ) {
				if ( INSTANCE == null ) {
					INSTANCE = new ServerFactory();
				}
			}
		}
		return INSTANCE;
	}

	public static Server createServer( ServerConfig pServerConfig ) {
		try {
			switch ( GameType.valueOf( pServerConfig.getType().toUpperCase() ) ) {
			case TF2:
				return new TF2Server( pServerConfig );
			case L4D:
				return new L4DServer( pServerConfig );
			case L4D2:
				return new L4D2Server( pServerConfig );
			case MINECRAFT:
				return new MinecraftServer( pServerConfig );
			default:
				return null;
			}
		} catch ( IllegalArgumentException e ) {
			throw new IllegalArgumentException( "No such game type." );
		}
	}
}
